package com.dada.repository.test;

import com.dada.domain.qos.AdminQO;
import com.dada.repository.AbstractTestRepository;
import com.dada.test.domain.tables.pojos.Admin;
import com.dada.test.domain.tables.records.AdminRecord;
import org.apache.commons.lang3.tuple.Pair;
import org.jooq.Table;
import org.jooq.UpdatableRecord;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * Created by jianweilin on 16/9/4.
 */
@Repository
public class AdminRepository extends AbstractTestRepository<AdminRecord> {

    @Override
    protected Pair<Class<AdminRecord>, Table<? extends UpdatableRecord>> mapping() {
        return Pair.of(AdminRecord.class, ADMIN);
    }

    /**
     *  根据id查询用户
     */
    public List<Admin> findById(Integer id){
        AdminQO query = AdminQO.builder().id(id).build();
        return dsl.select().from(ADMIN).where(query.conditions()).fetchInto(Admin.class);
    }
}
